//#define _CRT_SECURE_NO_WARNINGS 1
//
//#include<stdlib.h>
//int* twoSum(int* nums, int numsSize, int target, int* returnSize)
//{
//	int i = 0;
//	for (i = 0;i < numsSize;i++)
//	{
//		int j = 0;
//		for(j=i+1;j<numsSize;j++)
//			if (nums[i] + nums[j] == target)
//			{
//				int* ret = calloc(2, sizeof(int));
//				ret[0] = i;
//				ret[1] = j;
//				*returnSize = 2;
//				return ret;
//			}
//	}
//	*returnSize = 0;
//	return NULL;
//}

#define _CRT_SECURE_NO_WARNINGS 1

#include<stdlib.h>
int* twoSum(int* nums, int numsSize, int target, int* returnSize)
{
	int i = 0;
	
	for (i = 0;i < numsSize;i++)
	{
		int* ret = calloc(2, sizeof(int));
		int left = i+1;
		int right = numsSize - 1;
		while (left < right)
		{
			int mid = (left + right) / 2;
			if ((target - nums[i]) > nums[mid])
				left = mid + 1;
			else if ((target - nums[i]) < nums[mid])
				right = mid - 1;
			else
			{
				ret[0] = i;
				ret[1] = mid;
				*returnSize = 2;
				return ret;
			}
		}
	}
	*returnSize = 0;
	return NULL;
}